package model

import (
	"api-getaway/basic/config"
	"gorm.io/gorm"
)

// 视频表
type Video struct {
	gorm.Model
	Title        string `gorm:"type:varchar(30);not null;comment:'标题'"`
	Description  string `gorm:"type:varchar(50);not null;comment:'简介'"`
	CoverUrl     string `gorm:"type:varchar(100);not null;comment:'封面'"`
	CategoryId   int    `gorm:"type:int;not null;comment:'视频分类ID'"`
	TypeId       int    `gorm:"type:int;not null;comment:'视频类型ID'"`
	RegionId     int    `gorm:"type:int;not null;comment:'视频分类ID'"`
	Year         int    `gorm:"type:int;not null;comment:'发行年份'"`
	Actor        string `gorm:"type:varchar(50);not null;comment:'主演演员'"`
	Director     string `gorm:"type:varchar(50);not null;comment:'导演'"`
	PlayCount    int    `gorm:"type:int;not null;comment:'播放量'"`
	LikeCount    int    `gorm:"type:int;not null;comment:'点赞量'"`
	CollectCount int    `gorm:"type:int;not null;comment:'收藏量'"`
	CommentCount int    `gorm:"type:int;not null;comment:'评论量'"`
	Status       int    `gorm:"type:int;not null;comment:'审核状态'"`
}

func (v *Video) CreateVideo() error {
	return config.DB.Debug().Create(&v).Error
}

// 电视剧集表
type DramaEpisode struct {
	gorm.Model
	VideoId    int    `gorm:"type:int;not null;comment:'视频ID'"`
	EpisodeNum int    `gorm:"type:int;not null;comment:'剧集数'"`
	Title      string `gorm:"type:varchar(20);not null;comment:'剧集标题'"`
	Duration   int    `gorm:"type:int;not null;comment:'剧集时长'"`
}

// 分类表
type Category struct {
	gorm.Model
	Name string `gorm:"type:varchar(20);not null;comment:'分类名称'"`
}

// 类型表
type Type struct {
	gorm.Model
	Name string `gorm:"type:varchar(20);not null;comment:'类型名称'"`
}

// 地区表
type Region struct {
	gorm.Model
	Name string `gorm:"type:varchar(20);not null;comment:'地区名称'"`
}

// 观看历史表
type UserHistory struct {
	gorm.Model
	UserId    int `gorm:"type:int;not null;comment:'用户ID'"`
	VideoId   int `gorm:"type:int;not null;comment:'视频ID'"`
	EpisodeId int `gorm:"type:int;not null;comment:'剧集ID'"`
	Progress  int `gorm:"type:int;not null;comment:'播放进度'"`
}

func (h *UserHistory) CreateHistory() error {
	return config.DB.Debug().Create(&h).Error
}

// 视频审核表
type VideoReview struct {
	gorm.Model
	VideoId  int    `gorm:"type:int;not null;comment:'视频ID'"`
	Status   int    `gorm:"type:int;not null;comment:'审核状态 0-未审核 1-已审核 2-审核失败'"`
	Reason   string `gorm:"type:varchar(20);not null;comment:'审核原因'"`
	ReviewId int    `gorm:"type:int;not null;comment:'审核ID'"`
}

func (r *VideoReview) CreateVideoReview() error {
	return config.DB.Debug().Create(&r).Error
}

type Ranking struct {
	gorm.Model
	Number       int     `gorm:"type:int;not null;comment:'序号'"`
	Title        string  `gorm:"type:varchar(20);not null;comment:'标题'"`
	CoverUrl     string  `gorm:"type:varchar(100);not null;comment:'封面'"`
	PlayCount    int     `gorm:"type:int;not null;comment:'播放量'"`
	LikeCount    int     `gorm:"type:int;not null;comment:'点赞量'"`
	CollectCount int     `gorm:"type:int;not null;comment:'收藏量'"`
	CommentCount int     `gorm:"type:int;not null;comment:'评论量'"`
	HeatValue    float64 `gorm:"type:decimal(10,2);not null;comment:'热度值'"`
}
